package com.lgc.service.utils

import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide

/**
 * 项目适配用的BindAdapter
 */


/**
 * imageview支持图片加载 绑定
 */
@BindingAdapter("app:srcCompat", requireAll = false)
fun imgSrc(iv: ImageView, src: Any?){
    Glide.with(iv).load(src).into(iv)
}


@BindingAdapter("app:tint")
fun imgColor2(iv: ImageView, color:Int){
    if(color==0) return
    runCatching {
        iv.setColorFilter(iv.resources.getColor(color))
    }.onFailure {
        iv.setColorFilter(color)
    }
}


@BindingAdapter("android:textColor")
fun tvColor2(tv: TextView, color:Int){
    if(color==0) return
    runCatching {
        tv.setTextColor(tv.resources.getColor(color))
    }.onFailure {
        tv.setTextColor(color)
    }
}